//引入
const express = require('express');
const db = require('../../utils/db')

//配置路由器
const riqi = express.Router();

riqi.get('/baogao1/query', (req, res) => {
  const page = req.query.page;
  const count = req.query.count;
  const sql = `select * from t_riqi limit ${(page - 1) * count},${count}`;
  const sql2 = `select count(*) as total from t_riqi;`;
  db.query(sql, (err, data) => {
    if (err) {
      console.log(err)
      res.send({ error: 1, msg: err })
    } else {
      db.query(sql2, (err2, data2) => {
        if (err2) {
          console.log(err2)
          res.send({ error: 1, msg: err2 })
        } else {
          console.log(data2)
          res.send({ error: 0, msg: '查询成功', data: data, total: data2[0].total })
        }
      })
    }
  })
})

module.exports = riqi;